package com.ruoyi.web.controller.mall.mallInvoiceShop.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.mall.mallInvoiceShop.domain.MallInvoiceShop;
import com.ruoyi.web.controller.mall.mallInvoiceShop.service.IMallInvoiceShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商家开票规则Controller
 * 
 * @author ruoyi
 * @date 2021-01-18
 */
@Controller
@RequestMapping("/mall/mallInvoiceShop")
public class MallInvoiceShopController extends BaseController
{
    private String prefix = "mall/mallInvoiceShop";

    @Autowired
    private IMallInvoiceShopService mallInvoiceShopService;

//    @RequiresPermissions("mall:mallInvoiceShop:view")
    @GetMapping()
    public String mallInvoiceShop()
    {
        return prefix + "/mallInvoiceShop";
    }

    /**
     * 查询商家开票规则列表
     */
//    @RequiresPermissions("mall:mallInvoiceShop:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MallInvoiceShop mallInvoiceShop)
    {
        startPage();
        List<MallInvoiceShop> list = mallInvoiceShopService.selectMallInvoiceShopList(mallInvoiceShop);
        return getDataTable(list);
    }

    /**
     * 导出商家开票规则列表
     */
//    @RequiresPermissions("mall:mallInvoiceShop:export")
    @Log(title = "商家开票规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MallInvoiceShop mallInvoiceShop)
    {
        List<MallInvoiceShop> list = mallInvoiceShopService.selectMallInvoiceShopList(mallInvoiceShop);
        ExcelUtil<MallInvoiceShop> util = new ExcelUtil<MallInvoiceShop>(MallInvoiceShop.class);
        return util.exportExcel(list, "mallInvoiceShop");
    }

    /**
     * 新增商家开票规则
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商家开票规则
     */
//    @RequiresPermissions("mall:mallInvoiceShop:add")
    @Log(title = "商家开票规则", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MallInvoiceShop mallInvoiceShop)
    {
        return toAjax(mallInvoiceShopService.insertMallInvoiceShop(mallInvoiceShop));
    }

    /**
     * 修改商家开票规则
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MallInvoiceShop mallInvoiceShop = mallInvoiceShopService.selectMallInvoiceShopById(id);
        mmap.put("mallInvoiceShop", mallInvoiceShop);
        return prefix + "/edit";
    }

    /**
     * 修改保存商家开票规则
     */
//    @RequiresPermissions("mall:mallInvoiceShop:edit")
    @Log(title = "商家开票规则", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MallInvoiceShop mallInvoiceShop)
    {
        return toAjax(mallInvoiceShopService.updateMallInvoiceShop(mallInvoiceShop));
    }

    /**
     * 删除商家开票规则
     */
//    @RequiresPermissions("mall:mallInvoiceShop:remove")
    @Log(title = "商家开票规则", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String[] ids)
    {
        return toAjax(mallInvoiceShopService.deleteMallInvoiceShopByIds(ids));
    }
}
